<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客列表页</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_list.css">
    <script src="editor.md/lib/marked.min.js"></script>
    <script src="editor.md/lib/prettify.min.js"></script>
    <script src="editor.md/editormd.js"></script>
</head>
<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="image/logo.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 这个标签仅仅用于占位, 把这几个 a 标签挤到右侧去 -->
        <div class="spacer"></div>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写博客</a>
        <a href="logout">注销</a>
    </div>
    <!-- 页面主体部分 -->
    <div class="container">
        <!-- 左侧信息 -->
        <div class="container-left">
            <!-- 使用这个 .card 表示用户信息 -->
            <div class="card">
                <!-- 用户头像 -->
                <img src="image/国恩哥.jpg" alt="">
                <!-- 用户名 -->
                <h3>钊</h3>
                <a href="https://gitee.com/zhao-55" target="_blank">github 地址</a>
                <div class="counter">
                    <span>文章</span>
                    <span>分类</span>
                </div>
                <div class="counter">
                    <span>1</span>
                    <span>2</span>
                </div>
            </div>
        </div>
        <!-- 右侧信息 -->
        <div class="container-right">
            <!-- 表示一篇博客 -->
            
    
        </div>
    </div>
        <script src="./js/jquery.min.js"></script>
        <script>
            function getBlogs(){
                $.ajax({
                   type:'get',
                   url:'blog',
                   success:function(body){
                    let containerRight = document.querySelector('.container-right');
                    for(let blog of body){
                        //构造页面内容
                        let blogDiv = document.createElement('div');
                        blogDiv.className = 'blog';
                        //构造标题
                        let titleDiv = document.createElement('div');
                        titleDiv.className = 'title';
                        titleDiv.innerHTML = blog.title;
                        blogDiv.appendChild(titleDiv);
                        //构造发布时间
                        let dateDiv = document.createElement('div');
                        dateDiv.className = 'date';
                        dateDiv.innerHTML = blog.postTime;
                        blogDiv.appendChild(dateDiv);
                        //构造 博客 摘要
                        let descDiv = document.createElement('div');
                        descDiv.className = 'desc';
                        
                        descDiv.innerHTML = blog.content;
                        // descDiv.style = "display: none;"
                        blogDiv.appendChild(descDiv);
                       
                        let a = document.createElement('a');
                        a.innerHTML = '查看全文 &gt;&gt;';
                        a.href = 'blog_detail.html?blogId='+ blog.blogId;
                        blogDiv.appendChild(a);
                        //把blogDiv加到父元素
                        containerRight.appendChild(blogDiv);
                    }
                  }
                });
            }
            getBlogs();
            function checkLogin(){
                $.ajax({
                   type:'get',
                   url:'login',
                   success:function(body){
                    if(body.userId && body.userId > 0){
                        console.log("当前用户已经登录!");
                    }else{
                        location.assign('login.html');
                    }
                   }
                });
            }
            checkLogin();
        </script>
   
</body>
</html>